home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / awt / GraphicsEnvironment.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  6.7 KB  |  174 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)GraphicsEnvironment.java    1.34 98/10/16
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15.  
  16. package java.awt;
  17.  
  18. import java.awt.image.BufferedImage;
  19. import java.util.Hashtable;
  20. import java.util.Locale;
  21. import java.util.Map;
  22. import java.io.InputStream;
  23.  
  24. /**
  25.  *
  26.  * The <code>GraphicsEnvironment</code> class describes the collection
  27.  * of {@link GraphicsDevice} objects and {@link java.awt.Font} objects
  28.  * available to a Java(tm) application on a particular platform.
  29.  * The resources in this <code>GraphicsEnvironment</code> might be local
  30.  * or on a remote machine.  <code>GraphicsDevice</code> objects can be
  31.  * screens, printers or image buffers and are the destination of
  32.  * {@link Graphics2D} drawing methods.  Each <code>GraphicsDevice</code>
  33.  * has a number of {@link GraphicsConfiguration} objects associated with
  34.  * it.  These objects specify the different configurations in which the
  35.  * <code>GraphicsDevice</code> can be used.  
  36.  * @see GraphicsDevice
  37.  * @see GraphicsConfiguration
  38.  * @version 10 Feb 1997
  39.  */
  40.  
  41. public abstract class GraphicsEnvironment {
  42.     private static GraphicsEnvironment localEnv;
  43.  
  44.     /**
  45.      * This is an abstract class and cannot be instantiated directly.
  46.      * Instances must be obtained from a suitable factory or query method.
  47.      */
  48.     protected GraphicsEnvironment() {
  49.     }
  50.  
  51.     /**
  52.      * Returns the local <code>GraphicsEnvironment</code>.
  53.      * @return this <code>GraphicsEnvironment</code>.
  54.      */
  55.     public static GraphicsEnvironment getLocalGraphicsEnvironment() {
  56.     if (localEnv == null) {
  57.         String nm = (String) java.security.AccessController.doPrivileged
  58.         (new sun.security.action.GetPropertyAction
  59.          ("java.awt.graphicsenv", null));
  60.  
  61.         try {
  62.         localEnv =
  63.             (GraphicsEnvironment) Class.forName(nm).newInstance();
  64.         } catch (ClassNotFoundException e) {
  65.                 throw new Error("Could not find class: "+nm);
  66.             } catch (InstantiationException e) {
  67.                 throw new Error("Could not instantiate Graphics Environment: "
  68.                 + nm);
  69.             } catch (IllegalAccessException e) {
  70.                 throw new Error ("Could not access Graphics Environment: "
  71.                  + nm);
  72.             }
  73.         }
  74.  
  75.     return localEnv;
  76.     }
  77.  
  78.     /**
  79.      * Returns an array of all of the screen <code>GraphicsDevice</code>
  80.      * objects.
  81.      * @return an array containing all the <code>GraphicsDevice</code>
  82.      * objects that represent screen devices.
  83.      */
  84.     public abstract GraphicsDevice[] getScreenDevices();
  85.  
  86.     /**
  87.      * Returns the default screen <code>GraphicsDevice</code>.
  88.      * @return the <code>GraphicsDevice</code> that represents the
  89.      * default screen device.
  90.      */
  91.     public abstract GraphicsDevice getDefaultScreenDevice();
  92.  
  93.     /**
  94.      * Returns a <code>Graphics2D</code> object for rendering into the
  95.      * specified {@link BufferedImage}.
  96.      * @param img the specified <code>BufferedImage</code>
  97.      * @return a <code>Graphics2D</code> to be used for rendering into
  98.      * the specified <code>BufferedImage</code>.
  99.      */
  100.     public abstract Graphics2D createGraphics(BufferedImage img);
  101.  
  102.     /**
  103.      * Returns an array containing a one-point size instance of all fonts
  104.      * available in this <code>GraphicsEnvironment</code>.  Typical usage
  105.      * would be to allow a user to select a particular font.  Then, the
  106.      * application can size the font and set various font attributes by
  107.      * calling the <code>deriveFont</code> method on the choosen instance.
  108.      * <p>
  109.      * This method provides for the application the most precise control
  110.      * over which <code>Font</code> instance is used to render text.
  111.      * If a font in this <code>GraphicsEnvironment</code> has multiple
  112.      * programmable variations, only one
  113.      * instance of that <code>Font</code> is returned in the array, and
  114.      * other variations must be derived by the application.
  115.      * <p>
  116.      * If a font in this environment has multiple programmable variations,
  117.      * such as Multiple-Master fonts, only one instance of that font is
  118.      * returned in the <code>Font</code> array.  The other variations
  119.      * must be derived by the application.
  120.      * @return an array of <code>Font</code> objects.
  121.      * @see #getAvailableFontFamilyNames
  122.      * @see java.awt.Font
  123.      * @see java.awt.Font#deriveFont
  124.      * @see java.awt.Font#getFontName
  125.      * @since JDK 1.2
  126.      */
  127.     public abstract Font[] getAllFonts();
  128.  
  129.     /**
  130.      * Returns an array containing the names of all font families available
  131.      * in this <code>GraphicsEnvironment</code>.
  132.      * Typical usage would be to allow a user to select a particular family
  133.      * name and allow the application to choose related variants of the
  134.      * same family when the user specifies style attributes such
  135.      * as Bold or Italic.
  136.      * <p>
  137.      * This method provides for the application some control over which
  138.      * <code>Font</code> instance is used to render text, but allows the 
  139.      * <code>Font</code> object more flexibility in choosing its own best
  140.      * match among multiple fonts in the same font family.
  141.      * @return an array of <code>String</code> containing names of font
  142.      * families.
  143.      * @see #getAllFonts
  144.      * @see java.awt.Font
  145.      * @see java.awt.Font#getFamily
  146.      * @since JDK 1.2
  147.      */
  148.     public abstract String[] getAvailableFontFamilyNames();
  149.  
  150.     /**
  151.      * Returns an array containing the localized names of all font families
  152.      * available in this <code>GraphicsEnvironment</code>.
  153.      * Typical usage would be to allow a user to select a particular family
  154.      * name and allow the application to choose related variants of the
  155.      * same family when the user specifies style attributes such
  156.      * as Bold or Italic.
  157.      * <p>
  158.      * This method provides for the application some control over which
  159.      * <code>Font</code> instance used to render text, but allows the 
  160.      * <code>Font</code> object more flexibility in choosing its own best
  161.      * match among multiple fonts in the same font family.
  162.      * @param l a {@link Locale} object that represents a
  163.      * particular geographical, political, or cultural region
  164.      * @return an array of <code>String</code> objects containing names of
  165.      * font families specific to the specified <code>Locale</code>.
  166.      * @see #getAllFonts
  167.      * @see java.awt.Font
  168.      * @see java.awt.Font#getFamily
  169.      * @since JDK 1.2
  170.      */
  171.     public abstract String[] getAvailableFontFamilyNames(Locale l);
  172.  
  173. }
  174.